package com.lzy.webapi.facade;

import com.github.pagehelper.PageInfo;
import com.lzy.framework.core.datasource.multiple.DataSource;
import com.lzy.framework.core.orm.db.Pager;
import com.lzy.member.apis.MemberCheckLogServiceApi;
import com.lzy.member.dtos.MemberCheckLogDto;
import com.lzy.webapi.request.MemberCheckLogRequest;
import com.lzy.webapi.response.MemberCheckLogResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by WIN7 on 2018/4/8.
 */
@Component
public class MemberCheckLogFacade {
    public static final Logger LOGGER = LoggerFactory.getLogger(MemberCheckLogFacade.class);

    @Autowired
    MemberCheckLogServiceApi memberCheckLogServiceApi;

    @DataSource(name = DataSource.DATASOURCE_COMMON)
    public List<MemberCheckLogResponse> selectCheckLogList(MemberCheckLogRequest request, Long userId) {
        List<MemberCheckLogResponse> memberCheckLogResponseList = new ArrayList<>();
        Pager pager = new Pager();
        pager.setPageNum(request.getPageNum());
        pager.setPageSize(request.getPageSize());
        MemberCheckLogDto memberCheckLogDto = new MemberCheckLogDto();
        memberCheckLogDto.setCheckerId(userId);
        memberCheckLogDto.setType(request.getType());
        memberCheckLogDto.setTimeStr(request.getTimeStr());
        PageInfo<MemberCheckLogDto> pageInfo = memberCheckLogServiceApi.selectCheckLogList(pager,memberCheckLogDto);
        if(pageInfo != null && pageInfo.getList() != null && pageInfo.getList().size() > 0){
            List<MemberCheckLogDto> memberCheckLogDtoList = pageInfo.getList();
            for (MemberCheckLogDto mclDto:memberCheckLogDtoList) {
                MemberCheckLogResponse memberCheckLogResponse = new MemberCheckLogResponse();
                if(mclDto != null){
                    memberCheckLogResponse.setId(mclDto.getId());
                    memberCheckLogResponse.setCouponName(mclDto.getCouponName());
                    memberCheckLogResponse.setCouponPrice(mclDto.getCouponPrice());
                    memberCheckLogResponse.setCreateTime(mclDto.getCreateTime());
                    memberCheckLogResponseList.add(memberCheckLogResponse);
                }
            }
        }
        return memberCheckLogResponseList;
    }
}
